<?php
/**
 * 公共控制器
 */
namespace Controller;
use Core\Lib\Controller;
class CommonController extends Controller{
    /**
     * 构造函数
     * @todo 数据身份等验证
     */
    public function __construct() {
        parent::__construct();
        // token 验证
        $allow_token = ['UFgGlyPTiFytLhUVCbb6vAiGp4MDNU8I6e8uSxoGP+Y=', 'AFgGlyPTiFytLhUVCbb6vAiGp4MDNU8I6e8uSxoGP+Y='];        // 允许的token
        if(!array_key_exists('token', $this->post) || !in_array($this->post['token'], $allow_token)){
            $error = $this->ajaxReturnError(lang('TOKEN_ERROR'));
            $this->response->end($error);
        }

        // appid 验证
        $allow_appid = ['2018042554548', '2018042554549'];
        if(!array_key_exists('appid', $this->post) || !in_array($this->post['appid'], $allow_appid)){
            $error = $this->ajaxReturnError(lang('APPID_ERROR'));
            $this->response->end($error);
        }
    }
    
    /**
     * 返回成功
     * @param array $data 返回数据
     * @return json
     */
    public function ajaxReturnSuccess($data=''){
        $result = ['status'=>1, 'result'=>$data];
        return $this->ajaxReturn($result);
    }
    
    /**
     * 返回失败
     * @param array $data 返回数据
     * @return json
     */
    public function ajaxReturnError($data=''){
        $result = ['status'=>0, 'result'=>$data];
        return $this->ajaxReturn($result);
    }
}